package engine.newUi
{
	import flash.display.MovieClip;
	import flash.events.TimerEvent;
	import flash.filters.BitmapFilterQuality;
	import flash.filters.GlowFilter;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import flash.text.TextFormat;
	import flash.utils.Timer;
	import flash.utils.getTimer;
	
	import newx.NxSprite;
	import newx.StageInfo;
	import newx.com.ResManager;
	import newx.com.config.StaticIni;
	
	/**
	 *消息系统提示 
	 * @author gaoyq
	 * 
	 */
	public class MessageUI extends NxSprite
	{
		private static var _self	:MessageUI;
		private var _messageTxt	:TextField;
		private var _timer			:Timer;
		private var _textFormat	:TextFormat;
		
		
		private var _msgList		:Array=[];
		
		private var _oldTime		:int;
		/**背景底图**/
		private var _bgMc			:MovieClip;
		
		/**
		 * 当完成初始化工作之后调用
		 */
		public static function getInstance():MessageUI
		{
			if(_self == null)
			{
				_self	=	new MessageUI();
			}
			return _self;
		}
		
		public function MessageUI(popupUI:Boolean=true)
		{
			_timer	=	new Timer(3000,1);
			_timer.addEventListener(TimerEvent.TIMER_COMPLETE,onTimerFinish);
			_textFormat	=	new TextFormat();
			_textFormat.size			=	22;
			_textFormat.bold 			=	true;
			_textFormat.color			=	StaticIni.getIniVar("Css_txt_MessageUI", "txtStr");
			_messageTxt	=	new TextField();
			_messageTxt.mouseEnabled	=	false;
			_messageTxt.selectable		=	false;
			_messageTxt.width		=	StageInfo.rootW;
			_messageTxt.autoSize	=	TextFieldAutoSize.CENTER;
			var glow:GlowFilter		= 	new GlowFilter();
			glow.color 				= 	0x000000;
			glow.alpha 				= 	1;
			glow.blurX 				=	2;
			glow.blurY				= 	2;
			glow.strength			=	4;
			glow.quality			= 	BitmapFilterQuality.HIGH;
			_messageTxt.filters		=	[glow];
			_messageTxt.defaultTextFormat	=	_textFormat;
			_bgMc = ResManager.newResClass("CustomControl_0200") as MovieClip;
			addChild(_bgMc);
			addChild(_messageTxt);
			//hide();
			
			mouseChildren	=	mouseEnabled	=	false;
		}
		
		private function onTimerFinish(e:TimerEvent):void
		{
			_messageTxt.htmlText	=	""
			_timer.stop();
			hide();
			
			if( _msgList.length > 0 )
			{
				showInfo( _msgList.shift() );
			}else
			{
				_timer.delay = 3000;
			}
		}
		
		public function showInfo(value:String):void
		{
			if( getTimer() - _oldTime < 500 )
			{
				_msgList.push( value );
				
				_timer.delay = 550;
				return;;
			}
			
			if( _msgList.length > 0 )
			{
				_msgList.push( value );
				
				value = _msgList.shift();
			}
			_oldTime = getTimer();
			mouseChildren	=	mouseEnabled	=	false;
			_timer.reset();
			//IO.traceLog("Message Text:"+value);
			_messageTxt.htmlText	=	value;
			_messageTxt.setTextFormat(_textFormat);
			StageInfo.systemSpace.addChild(this);
			_bgMc.x = _messageTxt.x ;
			_bgMc.y = _messageTxt.y - 5;
			_bgMc.height = _messageTxt.height +10;
			_bgMc.width = _messageTxt.width;
			_timer.start();
		}
	}
}